#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main()
{
	int t;
	cin >> t;

	while (t--)
	{
		int n;
		cin>> n;
		vector<int> a(n);
		for (int i = 0; i < n; i++)
			cin >> a[i];
		sort(a.begin(), a.end());

		int ret = 0;
		for (int i = 0; i < n; i++)
		{
			for (int j = i + 1; j < n; j++)
				ret += a[j] - a[i];
		}

		cout << ret << endl;
	}

	return 0;
}